package com.sanley.coronavirus.service.iml;

import com.sanley.coronavirus.bo.Card;
import com.sanley.coronavirus.bo.CardContent;
import com.sanley.coronavirus.bo.PieSliceContent;
import com.sanley.coronavirus.dao.CureDao;
import com.sanley.coronavirus.dao.DeadDao;
import com.sanley.coronavirus.dao.PatientDao;
import com.sanley.coronavirus.dao.TouchDao;
import com.sanley.coronavirus.service.CureService;
import com.sanley.coronavirus.service.IndexPageService;
import com.sanley.coronavirus.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @Author: ming
 * @create: 2022-10-15 15:55
 * @program: coronavirus
 */
@Service
public class IndexPageServiceImpl implements IndexPageService {

    @Autowired
    private PatientDao patientDao;

    @Autowired
    private CureDao cureDao;

    @Autowired
    private DeadDao deadDao;

    @Autowired
    private TouchDao touchDao;


    @Override
    public List<Card> getCards() {

        //查找数量
        int pN = patientDao.number();
        int pCN = patientDao.currentNumber();
        int cN = cureDao.number();
        int dN = deadDao.number();
        int tN = touchDao.number();
        int tCN = touchDao.currentNumber();
        //计算百分比
        double cR = (double) Math.round(((double) cN / (double) pN) * 100);
        double dR = (double) Math.round(((double) dN / (double) pN) * 100);

        Card card1 = new Card(Arrays.asList(new CardContent("现存确诊人数", pCN), new CardContent("累计确诊人数", pN)), "#0073b7", "/");
        Card card2 = new Card(Arrays.asList(new CardContent("治愈人数", cN), new CardContent("治愈率", cR + "%")), "#00b755", "/");
        Card card3 = new Card(Arrays.asList(new CardContent("死亡人数", dN), new CardContent("死亡率", dR + "%")), "#d71438", "/");
        Card card4 = new Card(Arrays.asList(new CardContent("现存隔离人数", tCN), new CardContent("累计隔离人数", tN)), "#ffd235", "/");
        return Arrays.asList(card1, card2, card3, card4);
    }

    @Override
    public List<PieSliceContent> getPieChartData() {
        int pCN = patientDao.currentNumber();
        int dN = deadDao.number();
        int cN = cureDao.number();
        HashMap<String, Object> map1 = new HashMap<>();
        map1.put("color", "#0073b7");

        HashMap<String, Object> map2 = new HashMap<>();
        map1.put("color", "#d71438");

        HashMap<String, Object> map3 = new HashMap<>();
        map1.put("color", "#00b755");
        return Arrays.asList(new PieSliceContent("现存确诊人数", pCN, map1), new PieSliceContent("死亡人数", dN, map2), new PieSliceContent("治愈人数", cN, map3));
    }
}
